//https://www.bilibili.com/video/BV1d54y1f7B3?spm_id_from=333.788.videopod.episodes&vd_source=d6fe65f095f01f05591e89d810720ccc&p=20
// 2024-10-22

import java.util.Arrays;

public class P031_香槟塔_模拟 {

    public static void main(String[] args) {
        System.out.println(fun(5,2,1));
        System.out.println(fun(5,2,2));

    }

    private static double fun(int poured,int query_row,int query_glass) {
        double[][] ca = new double[100][100];
        //初始化
        ca[0][0] = poured;
        for (int r = 0; r <= query_row; r++) {
            for (int l = 0; l <= r; l++) {
                double d =  (ca[r][l] - 1.0)/2; //溢出的酒量
                if (d > 0) {
                    ca[r+1][l] += d;//左下角杯子
                    ca[r+1][l+1] += d;//右下角杯子
                }
            }
        }
        return Math.min(1,ca[query_row][query_glass]);
    }
}
